LOCAL_TARGET_NAME := ubuntu:focal

LOCAL_DOCKER_REPO ?= docker
LOCAL_DOCKER_TAG := $(LOCAL_DOCKER_REPO)/$(LOCAL_TARGET_NAME)

LOCAL_DIR_SRC := src
LOCAL_FILE_ARCHIVE := ubuntu-base-20.04.5-base-amd64.tar.gz

LOCAL_DOCKER_FILE := $(LOCAL_DIR_SRC)/Dockerfile
LOCAL_DOCKER_ARCHIVE := $(LOCAL_DIR_SRC)/$(LOCAL_FILE_ARCHIVE)
LOCAL_MIRROR_URL := https://cdimage.ubuntu.com/ubuntu-base/releases/20.04/release/$(LOCAL_FILE_ARCHIVE)

all: build

build:
	@echo ">>>>>>>>> $@ $(LOCAL_TARGET_NAME) ... <<<<<<<<<"
	@if [ ! -f "$(LOCAL_DOCKER_ARCHIVE)" ]; then \
		wget -nv --show-progress ${LOCAL_MIRROR_URL} -O ${LOCAL_DOCKER_ARCHIVE}; \
	fi
	@sha256sum -c $(LOCAL_DIR_SRC)/SHA256SUMS >/dev/null 2>&1 || \
		echo "******************************************************" || \
		echo "Error: $(LOCAL_DOCKER_ARCHIVE) sha256sum."            || \
		echo "******************************************************" || \
		exit "$$?";
	@sudo docker build --no-cache --rm -t $(LOCAL_DOCKER_TAG) -f $(LOCAL_DOCKER_FILE) $(LOCAL_DIR_SRC)

push:
	@echo ">>>>>>>>> $@ $(LOCAL_TARGET_NAME) ... <<<<<<<<<"

clean:
	@echo ">>>>>>>>> $@ $(LOCAL_TARGET_NAME) ... <<<<<<<<<"
	@sudo docker image rm -f $(LOCAL_DOCKER_TAG) && sudo docker image prune -f

.PHONY: all build push clean
